package com.fs.groupSeven.service.impl;

import com.fs.groupSeven.Dao.CollegeDao;
import com.fs.groupSeven.pojo.College;
import com.fs.groupSeven.service.CollegeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service
public class CollegeServiceImpl implements CollegeService {
    private CollegeDao collegeDao;

    @Autowired
    public CollegeServiceImpl(CollegeDao collegeDao){
        this.collegeDao = collegeDao;
    }
    @Override
    public List<College> getAll() {
        return collegeDao.querycollegeList();
    }

    @Override
    public List<String> queryCollegeName() {
        return collegeDao.queryCollegeName();
    }

    @Override
    public Set<College> getUserThatAddressLike(String collegename) {
        return collegeDao.queryByColumn(collegename);
    }

    @Override
    public boolean addOne(College college) {
        int result = collegeDao.insertByCollege(college);
        return result>0;
    }

    @Override
    public College getOneByUserId(Integer collegeId) {
        College college = collegeDao.queryById(collegeId);
        return college;
    }

    @Override
    public boolean updateOne(College college) {
        int result = collegeDao.updateByCollege(college);
        return result>0;
    }

    @Override
    public boolean deleteOneById(Integer collegeId) {
        int result = collegeDao.deleteById(collegeId);
        return result>0;
    }

    @Override
    public PageInfo<College> getUsersByPage(Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<College> collegeList = collegeDao.querycollegeList();
        System.out.println(collegeList.size());
        PageInfo<College> pageInfo = new PageInfo<>(collegeList);
        return pageInfo;
    }
}
